package com.siwei.mes.service.experiment.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.experiment.ExperimentYearConfig;
import com.siwei.mes.mapper.experiment.ExperimentYearConfigMapper;
import com.siwei.mes.service.experiment.ExperimentYearConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 试验委托当年配置记录(ExperimentYearConfig)表服务实现类
 *
 * @author linzi
 * @since 2024-08-10 13:59:26
 */
@Service
public class ExperimentYearConfigServiceImpl implements ExperimentYearConfigService {
    @Resource
    private ExperimentYearConfigMapper experimentYearConfigMapper;

    @Override
    public Long create(ExperimentYearConfig entity) {
        experimentYearConfigMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(ExperimentYearConfig entity) {
        ExperimentYearConfig experimentYearConfig = experimentYearConfigMapper.selectByPrimaryKey(entity.getId());
        assertTrue(experimentYearConfig == null, "试验委托当年配置记录信息不存在");
        experimentYearConfigMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        ExperimentYearConfig experimentYearConfig = experimentYearConfigMapper.selectByPrimaryKey(id);
        assertTrue(experimentYearConfig == null, "试验委托当年配置记录信息不存在");
        experimentYearConfigMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<ExperimentYearConfig> getPage(PageQuery<ExperimentYearConfig, ExperimentYearConfig> query) {
        ExperimentYearConfig searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> experimentYearConfigMapper.getList(searchParam));
    }

    @Override
    public ExperimentYearConfig loadById(Long id) {
        return experimentYearConfigMapper.loadById(id);
    }

    @Override
    public List<ExperimentYearConfig> getAll(ExperimentYearConfig entity) {
        return experimentYearConfigMapper.getList(entity);
    }
}
